# Contributor: Paul Onyschuk <blink@bojary.koba.pl>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: David Demelier <markand@malikania.fr>
pkgname=fossil
pkgver=2.24
pkgrel=1
pkgdesc="Simple, high-reliability, distributed software configuration management"
url="https://www.fossil-scm.org"
arch="all"
license="BSD-2-Clause"
makedepends="openssl-dev>3 tcl-dev zlib-dev"
checkdepends="coreutils ed tcl-lib sqlite-tcl"
subpackages="$pkgname-bash-completion $pkgname-zsh-completion"
source="https://www.fossil-scm.org/home/tarball/version-$pkgver/fossil-src-$pkgver.tar.gz
	fix-tests.patch
	"
patch_args="-p0"
builddir="$srcdir/$pkgname-src-$pkgver"

prepare() {
	default_prepare

	# update autosetup-config.{sub/guess} to support loongarch64-alpine-linux-musl
	local sharedir="${ABUILD_SHAREDIR:-/usr/share/abuild}"
	cp -v "$sharedir"/config.sub autosetup/autosetup-config.sub
	cp -v "$sharedir"/config.guess autosetup/autosetup-config.guess
}

build() {
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--json \
		--with-th1-docs \
		--with-th1-hooks \
		--with-tcl=1 \
		--with-tcl-private-stubs
	make TCC="${CC:-gcc} $CFLAGS"
}

check() {
	export USER="${USER:-$(id -un)}"
	make TESTFLAGS="-verbose" test
}

package() {
	install -Dm 755 "$pkgname" "$pkgdir/usr/bin/$pkgname"

	# add shell completions
	install -Dm644 tools/fossil-autocomplete.bash \
		"$pkgdir"/usr/share/bash-completion/completions/fossil
	install -Dm644 tools/fossil-autocomplete.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_fossil
}

sha512sums="
7fc7de7d947b0946866df38c6cb2215f6452d31903cae6470bb4a692816b2803eb66ea372280256e5cd00759e4d02a0ae459de2f56f39af10e873579d53d33ee  fossil-src-2.24.tar.gz
2ce139acca006a754616409e2b713e814d7daf3633c3171e5ac2f98778fcb990638a4bb2037e2c02e7e3e9227fd1f7e0fad33e7ed8f98cc9a0fdc2f698629ccf  fix-tests.patch
"
